package com.cloudlead.utils.scheduler.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.quartz.utils.ConnectionProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author dean.lu
 * 
 *         为Quartz提供数据库连接 为了融入我们的框架而做
 * 
 */
public class ScheduleConnectionProvider implements ConnectionProvider {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(ScheduleConnectionProvider.class);

	private static DataSource dataSource; // 数据源

	/**
	 * 设置数据源
	 */
	public static synchronized void setDataSource(DataSource ds) {
		dataSource = ds;
		if (dataSource != null) {
			LOGGER.info("Set schedule datasource: " + dataSource.toString());
		} else {
			LOGGER.info("Set schedule datasource null");
		}
	}

	@Override
	public Connection getConnection() throws SQLException {
		return dataSource.getConnection();
	}

	@Override
	public void shutdown() throws SQLException {
		LOGGER.info("Shutdown connection provider");
	}

	@Override
	public void initialize() throws SQLException {
		
	}

}
